/******************************************************************************
* File description: maintenance.qml
* Function: 维护页面
* Current Version: 1.0.0
* Author: 张宇轩
* Date: 2024-08-28
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14
import QtGraphicalEffects 1.14

Item {
    id: root

    /* property 定义开始 */
    // 私有
    // 维护左侧图片和文字对应
    property var _infosMapper: {"热盖": "qrc:/icons/regai.png", "荧光检测": "qrc:/icons/yingguang.png", "加热块": "qrc:/icons/jiarekuai.png"}
    // 文字数组
    property var _infosList: ["热盖", "荧光检测", "加热块"]

    // 信号
    // 其他维护
    signal othersMaintenance();
    signal returnSig();
    signal selfChecking();
    /* property 定义结束 */

    // 顶部导航栏
    TabbarNav {
        id: tabNav
        width: parent.width
        isEnable: true
        title: "维护校准"

        onReturnSig: {
            console.log("tabbar nav")
            root.returnSig()
        }
        z: 999
    }

    ColumnLayout {
        anchors.fill: parent
        spacing: 0

        // 主体部分
        Rectangle {
            id: mainPart
            Layout.fillWidth: true
            Layout.preferredHeight: parent.height - btnContainer.height
            Layout.alignment: Qt.AlignTop

            // 背景
            Rectangle {
                anchors.fill: parent
                LinearGradient {
                    anchors.fill: parent
                    start: Qt.point(0, 0)
                    end: Qt.point(0, height)
                    gradient: Gradient {
                        GradientStop {position: 0.0; color: "#007BD8"}
                        GradientStop {position: 1.0; color: "#001A5A"}
                    }
                }
            }

            // 内容
            Item {
                anchors {
                    fill: parent
                    topMargin: 16 + tabNav.implicitHeight
                    rightMargin: 16
                    bottomMargin: 16
                    leftMargin: 5
                }

                RowLayout {
                    anchors.fill: parent
                    spacing: 5

                    // 图片区域
                    Item {
                        id: infoContainer
                        Layout.preferredWidth: 258
                        Layout.fillHeight: true

                        // 图片
                        Image {
                            id: infoIcon
                            width: parent.width
                            height: 258
                            anchors.verticalCenter: parent.verticalCenter
                            mipmap: true
                            smooth: true
                            fillMode: Image.PreserveAspectFit
                            source: root._infosMapper[infoText.text]
                        }

                        // 文字
                        Text {
                            id: infoText
                            anchors {
                                horizontalCenter: parent.horizontalCenter
                                top: infoIcon.bottom
                                topMargin: -30
                            }
                            text: "热盖"
                            font.pixelSize: 18
                            color: "#FFFEFEFE"
                        }
                    }

                    // 内容区域
                    Item {
                        id: contentCon
                        Layout.fillWidth: true
                        Layout.fillHeight: true

                        ColumnLayout {
                            anchors.fill: parent
                            spacing: 16

                            // tabbar
                            MaintenanceTabBar {
                                id: contentTabBar
                                Layout.fillWidth: true
                                Layout.preferredHeight: 44
                                barTitleList: ["热盖", "荧光检测", "加热块"]
                                onCurrentIndexChanged: {
                                    contentStackLayout.currentIndex = index
                                    infoText.text = root._infosList[index]
                                }

                                Component.onCompleted: {

                                }
                            }

                            // tabview容器
                            Rectangle {
                                id: tabViewContainer
                                Layout.fillWidth: true
                                Layout.fillHeight: true
                                color: "#FFD2EBFF"
                                border.width: 0
                                clip: true
                                layer.enabled: true
                                layer.effect: OpacityMask {
                                    maskSource: Rectangle {
                                        width: tabViewContainer.width
                                        height: tabViewContainer.height
                                        radius: 12
                                    }
                                }

                                // tabview
                                StackLayout {
                                    id: contentStackLayout
                                    anchors.fill: parent

                                    // 热盖
                                    MaintenanceTabWidgetReGai {
                                        id: reGaiTabWidget
                                        Layout.fillWidth: true
                                        Layout.fillHeight: true
                                    }

                                    // 荧光
                                    MaintenanceTabWidgetYingGuang {
                                        id: yingGuangTabWidget
                                        Layout.fillWidth: true
                                        Layout.fillHeight: true
                                    }

                                    // 加热块
                                    MaintenanceTabWidgetJiaReKuai {
                                        id: jiaReKuaiTabWidget
                                        Layout.fillWidth: true
                                        Layout.fillHeight: true
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        // 按钮部分
        Rectangle {
            id: btnContainer
            Layout.fillWidth: true
            Layout.preferredHeight: 80

            RowLayout {
                anchors.fill: parent
                anchors.rightMargin: 16
                anchors.leftMargin: 16

                PureButton {
                    id: resetInitBtn
                    pureText: "恢复初始(R)"
                    Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
                }

                PureButton {
                    id: otherBtn
                    pureText: "其他维护(O)"
                    Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
                    onReleased: {
                        root.othersMaintenance()
                    }
                }

                PureButton {
                    id: selfCheckingBtn
                    pureText: "设备自检(O)"
                    Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
                    onReleased: {
                        root.selfChecking()
                    }
                }

                CustomHorSpacerItem {}

                PureButton {
                    id: resetBtn
                    pureText: "复位(R)"
                    Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
                }

                GradientButton {
                    id: saveBtn
                    gradText: "保存(S)"
                    Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
                }
            }
        }

    }
}
